/*
 *  SPAGL Copyright (C) 2008 Sam Pottinger
 *  This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser 
 *  General Public License as published by the Free Software Foundation; either version 2.1 of the License, or 
 *  (at your option) any later version. This library is distributed in the hope that it will be useful, but 
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *  See the GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License along with this library; if not, 
 *  write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */

package spagswing;

import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.WindowEvent;

import javax.swing.event.ChangeEvent;
import javax.swing.event.DocumentEvent;
import javax.swing.event.ListSelectionEvent;

import spagcore.SpaglCoreEvent;

/**
 * An factory-like object for abstract use of various events as part of the
 * Spagl event system for swing
 * @author Sam Pottinger
 */
public class SpaglEvent implements SpaglCoreEvent {
	
	Object nativeEvent;
	int eventType;
	Object sourceObject;
	
	/**
	 * The contstructor called for an ActionEvent
	 * @param e the ActionEvent
	 * @see ActionEvent
	 */
	public SpaglEvent(ActionEvent e)
	{
		nativeEvent = e;
		sourceObject = e.getSource();
		eventType = SELECTION_EVENT;
	}
	
	/**
	 * The contstructor called for an ListSelectionEvent
	 * @param e the ListSelectionEvent
	 * @see ListSelectionEvent
	 */
	public SpaglEvent(ListSelectionEvent e)
	{
		nativeEvent = e;
		sourceObject = e.getSource();
		eventType = SELECTION_CHANGED_EVENT;
	}
	
	/**
	 * The contstructor called for an DocumentEvent
	 * @param e the DocumentEvent
	 * @see DocumentEvent
	 */
	public SpaglEvent(DocumentEvent e)
	{
		nativeEvent = e;
		sourceObject = e.getDocument();
		eventType = TEXT_CHANGED_EVENT;
	}
	
	/**
	 * The contstructor called for a ChangeEvent
	 * @param e the ChangeEvent
	 * @see DocumentEvent
	 */
	public SpaglEvent(ChangeEvent e)
	{
		nativeEvent = e;
		sourceObject = e.getSource();
		eventType = VALUE_CHANGED_EVENT;
	}
	
	/**
	 * The contstructor called for an ItemListener
	 * @param e the ItemEvent
	 * @see ItemEvent
	 */
	public SpaglEvent(ItemEvent e)
	{
		nativeEvent = e;
		sourceObject = e.getSource();
		eventType = TEXT_CHANGED_EVENT;
	}
	
	/**
	 * The constructor called for a WindowEvent
	 * @param e the WindowEvent
	 * @param newEventType the specific type of WindowEvent
	 * @see WindowEvent
	 */
	public SpaglEvent(WindowEvent e, int newEventType)
	{
		nativeEvent = e;
		sourceObject = e.getSource();
		eventType = newEventType;
	}
	
	/**
	 * Return the specific event represented by this wrapper
	 */
	public Object getEvent()
	{
		return nativeEvent;
	}
	
	/**
	 * Get the integer representation for the event being wrapped
	 */
	public int getEventType()
	{
		return eventType;
	}
	
	/**
	 * Get the object that called/generated the event
	 */
	public Object getSourceObject()
	{
		return sourceObject;
	}

}
